package com.ckm.aop;

import com.ckm.annotation.MongoDS;
import com.ckm.context.DynamicMongoContextHolder;
import com.ckm.datasource.DynamicMongoFactory;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

@Aspect
@Component
public class DynamicSwitchAop {

    @Autowired
    private DynamicMongoFactory dynamicMongoFactory;

    @Pointcut("@annotation(com.ckm.annotation.MongoDS)")
    public void run(){}

//    @Around("run()")
//    public Object around(ProceedingJoinPoint joinPoint)  throws Throwable {
//        MongoDS annotation = ((MethodSignature) joinPoint.getSignature()).getMethod().getAnnotation(MongoDS.class);
//        String value = annotation.value();
//        DynamicMongoContextHolder.setMongoContext(value);
//        Object proceed = joinPoint.proceed();
//        System.out.println("-------------------");
//        DynamicMongoContextHolder.pollMongoContext();
//        return proceed;
//    }
}
